import re

def extract_table_names_from_sql(sql):
    table_names = set()

    # 正则表达式模式用于匹配表名
    pattern = r'\b(?:FROM|JOIN|UPDATE|INTO)\s+([^\s,;\(\)]+)'

    matches = re.findall(pattern, sql, re.IGNORECASE)
    table_names.update(matches)

    return table_names

def extract_sql_from_file(file_path):
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            content = file.read()

            return content
    except Exception as e:
        print(f"Error: {e}")
        return ""

if __name__ == '__main__':
    file_path = "C:\\Users\\asus\\Desktop\\709\\diff\\2023-08-10.sql"  # 替换成你的文件路径
    sql_content = extract_sql_from_file(file_path)

    table_names = extract_table_names_from_sql(sql_content)

    if table_names:
        print("Distinct Table Names:")
        for idx, table in enumerate(table_names, start=1):
            print(f"{idx}. {table}")
    else:
        print("No table names found in the provided SQL content.")
